﻿using DevExpress.Utils;
using DevTeam;
using Extensions;
using System;
using System.Data;
using System.Drawing;

namespace ConfOrder.Shirt
{
    public partial class SendFabricOrder : XForm
    {
        DataTable dt;
        public SendFabricOrder(DataTable dt)
        {
            InitializeComponent();
            this.dt = dt;
        }

        private void SendFabricOrder_Load(object sender, EventArgs e)
        {
            this.MainToolbar.Visible = true;

            if (!dt.Columns.Contains("QtyToOrder"))            
                dt.Columns.Add("QtyToOrder", typeof(decimal));

            foreach (DataRow r in dt.Rows)
                r["QtyToOrder"] = r["MissingQty"];
            
            gridView1.Init(dt);
            gridView1.MakeReadOnly("QtyToOrder");
            btnSubmit.ItemClick += btnSubmit_ItemClick;

            gridView1.RowCellStyle += gridView1_RowCellStyle;

            gridView1.MakeColumnInvisible("IdleQty", "OtherQty", "WaitingForRsv", "ReservedQty");
            gridView1.FormatAsNumber(1, "RequiredQty", "ProjectedQty", "WaitingForOrd", "OrderedQty", "MissingQty", "QtyToOrder");
            gridView1.AddSummary("RequiredQty", "ProjectedQty", "WaitingForOrd", "OrderedQty", "MissingQty", "QtyToOrder");

            gridView1.BestFitColumns();
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
            {
                switch (e.Column.FieldName)
                {
                    case "QtyToOrder":
                    case "ProductId":
                        e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                        return;
                }
            }
        }

        public string xml = string.Empty;
        void btnSubmit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            xml = gridView1.DataTable().Serialize();
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}
